<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="example">
    <div class="layui-form-item">
        <label class="layui-form-label required">ID</label>
        <div class="layui-input-block">
            <input type="number" name="id" lay-verify="required" lay-reqtext="房产ID不能为空" placeholder="请输入房产ID" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">所属小区</label>
        <div class="layui-input-block">
            <!--            <input type="text" name="housePlot" lay-verify="required" lay-reqtext="所属小区不能为空" placeholder="请输入所属小区" value="" class="layui-input">-->
            <select name="plotName" lay-filter="plotName"  lay-verify="required" lay-reqtext="所属小区不能为空" id="plotName" >
                <option value="" disabled>请选择所属小区</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">栋数编号</label>
        <div class="layui-input-block">
            <input type="text" name="cellNum" lay-verify="required" lay-reqtext="栋数不能为空" placeholder="请输入房产栋数" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">总户数</label>
        <div class="layui-input-block">
            <input type="number" name="cellFamily" lay-verify="required" lay-reqtext="房产编号不能为空" placeholder="请输入房产编号" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label ">描述</label>
        <div class="layui-input-block">
            <input type="text" name="cellDetail"  value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label ">创建时间</label>
        <div class="layui-input-block">
            <input type="date" name="cellTime"  value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            $ = layui.$;

        //发送ajax异步请求，获取所有部门信息
        $.ajax({
            url:"/plot?method=all",
            success:function(res){
                //将获取到的数据渲染到下拉列表中
                if(res.code == 0){
                    $.each(res.data,function(index,value){//value = plot对象
                        $("#plotName").append(`<option value="${value.plotName}">${value.plotName}</option>`)
                    })
                    //动态获取到数据，需要对表单进行重新渲染才能生效
                    form.render();
                }
            }
        })


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            //发送ajax异步请求
            $.ajax({
                url:"/cell?method=add",
                data:{
                    info:JSON.stringify(data.field)
                },
                type:"POST",
                complete:function(){   //complete  无论是否成功的情况
                    //通过父页面关闭弹出层
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                }
            })
            return false;
        });
    });
</script>
</body>
</html>